package android.net;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import java.util.ArrayList;
import java.util.List;

/**
 * @author slc
 * @date 2022/03/29 上午 11:21
 */
public class ConnectivityManager extends Service {
    public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
    private NetworkInfo netWork;
    private final List<NetworkCallback> networkCallbackList = new ArrayList<>();

    public ConnectivityManager() {
        netWork = new NetworkInfo();
        netWork.setConnected(true);
    }

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    public void registerDefaultNetworkCallback(NetworkCallback networkCallback) {
        networkCallbackList.add(networkCallback);
    }

    public void unregisterNetworkCallback(NetworkCallback networkCallback) {
        networkCallbackList.remove(networkCallback);
    }

    public NetworkInfo getActiveNetworkInfo() {
        return netWork;
    }

    public static class NetworkCallback {
        public void onAvailable(Network networkInfo) {
        }

        public void onLost(Network network) {

        }

        public void onUnavailable() {
        }

    }
}
